//
//  CZBKGuideCell.m
//  CZ彩票
//
//  Created by apple on 15/8/28.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "GuideCell.h"
#import "MainController.h"


@interface GuideCell ()
@property (nonatomic, strong) UIImageView *imgViewBg;

// 创建一个立即体验按钮
@property (nonatomic,strong) UIButton *startButton;
@end

@implementation GuideCell


- (void)setStartButtonVisibleWithIndex:(int)idx count:(int)count {
    if (idx == count - 1) {
        self.startButton.hidden = NO;
    } else {
        self.startButton.hidden = YES;
    }
}
- (UIButton *)startButton {
    if (_startButton == nil) {
        _startButton = [[UIButton alloc] init];
        [_startButton setTitle:@"立即体验" forState:UIControlStateNormal];
        _startButton.layer.cornerRadius = 9;
        _startButton.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor whiteColor]);
        _startButton.layer.borderWidth = 1;
        // 为立即体验按钮注册一个单击事件
        [_startButton addTarget:self action:@selector(didClickStartButton) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_startButton];
    }
    return _startButton;
}

- (void)didClickStartButton {

    MainController *mainVC = [[MainController alloc] init];
    self.window.rootViewController = mainVC;
}


- (void)setImage:(UIImage *)image {
    _image = image;
    self.imgViewBg.image = image;
}

- (UIImageView *)imgViewBg {
    if (_imgViewBg == nil) {
        _imgViewBg = [[UIImageView alloc] init];
        [self.contentView addSubview:_imgViewBg];
    }
    return _imgViewBg;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imgViewBg.frame = self.bounds;
    
    CGFloat w = 120;
    CGFloat h = 30;
    CGFloat x = (self.bounds.size.width - w) * 0.5;
    CGFloat y = self.bounds.size.height * 0.8 + 25;
    self.startButton.frame = CGRectMake(x, y, w, h);

    
}
@end
